package wviz.index;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.TokenFilter;
//import org.apache.lucene.analysis.p
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;


import java.io.IOException;
import java.util.Stack;

public class StemFilter extends TokenFilter {
	private final TermAttribute termAtt;
	private PorterStemmer stemmer = new PorterStemmer();
	//private StemmingInformation stemInformation = new StemmingInformation();

	public StemFilter(TokenStream input) {
		super(input);
		this.termAtt = addAttribute(TermAttribute.class);

	}

	@Override
	public boolean incrementToken() throws IOException {

		if (!input.incrementToken()) {
			System.out.println("its false");
			return false;
		}

		String originalForm = termAtt.term();
		String stemmedWord = stemmer.stem(originalForm);
		StemmingInformation.addWord(stemmedWord, originalForm);
		termAtt.setTermBuffer(stemmedWord);
		return true;
	}
}
